<include file="Index/header" />
<body class="body">
<include file="Index/picture" />
	<div class="login_box">
    	<p>请使用E-MBA云APP账号登录</p>
    	<input type="text" id="user_phone" placeholder="手机号"/>
        <input type="password" id="user_password" placeholder="密码"/>
        <p class="text"><a href="#"  class="news" onClick="javascript:window.location.href='/Index/findPassword?community_id={$Think.get.community_id}&invite_id={$Think.get.invite_id}'">忘记密码？</a></p>
        <button type="button" value="" onClick="checkLogin();return false;">登录</button>
        <button type="button" value="" class="news" onClick="javascript:window.location.href='/Index/reg?community_id={$Think.get.community_id}&invite_id={$Think.get.invite_id}'">注册新用户</button>
    </div>
    <include file="Index/down" />
</body>
</html>
<script type="text/javascript">
	$(function($) {
		//publicPushNotice('','100000');
		//ajaxCommunityList();
		//光标默认定位
	})
	function checkLogin(){
		var user_phone = $.trim($("#user_phone").val());
		var user_password = $.trim($("#user_password").val());
		if (user_phone == '' || user_phone == undefined) {
			alert("账号不能为空");
			return false;
		}
		if (user_phone) {
			var reg_phone = /^[0-9]{11}$/;
			if (!reg_phone.exec(user_phone)) {
				alert("请输入正确的手机号码！");
				return false;
			}
		}
		if(user_password == '' || user_password == undefined){
			alert("密码不能为空");
			return false;
		}
		var json_data = {
			user_phone : user_phone,
			user_password : user_password
		};
		$.post("/Index/login/?rand=" + Math.random(), json_data, function(data) {
			if (data.status == 0) {
				var community_id = "{$Think.get.community_id}";
				joinCommunity(community_id);
			}else {
				alert(data.info);
			}
			return false;
		}, "json");
	
	}
	
	function joinCommunity(community_id){
		var host = 'http://'+window.location.host;
		invite_id = "{$Think.get.invite_id}";
		var post_data={'community_id':community_id,'invite_id':invite_id};
/* console.log(post_data);
return false; */
		$.ajax({
			type: "POST",
			url:"/Index/joinCommunity",
			data: post_data,
			success: function(data){
				if(data.status == '0'){
					if(data.data == 1){
						alert("您已加入过该社群");
						window.location.href= 'http://'+window.location.host+"/Index/myInvitation?community_id="+community_id+"&invite_id="+data.info;
	                }else if(data.data == 2){
	                	window.location.href= host+"/Index/only";
	                }else{
	                	//var usl= host+"/Index/getInvitation?community_id="+community_id+"&community_name="+data.info;
	                	publicPushNotice("恭喜你，社群加入成功！",community_id,data.info);
	                }
				}else{
	                alert(data.info);
	                if(data.data != ''){
	                	window.location.href = 'http://'+window.location.host+"/Index/myInvitation?community_id="+community_id+"&invite_id="+data.data;
	                }
	                return false;
	            }
	
	        },
	        dataType:"json"
	    });
	}
	//推送调用
	function publicPushNotice(notice,community_id,community_name){
		var host = 'http://'+window.location.host;
		var post_data={};
		$.ajax({
			type: "POST",
			url:"/Index/publicPushNotice",
			data: post_data,
			success: function(data){
				if(data.status == '0'){
					alert(notice);
					window.location.href = host+"/Index/getInvitation?community_id="+community_id+"&community_name="+community_name;

				}else{
	                alert(data.info);
	                return false;
	            }
	
	        },
	        dataType:"json"
	    });
	}
</script>